package com.thinking.live.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.request.AlipayTradeCreateRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.thinking.live.config.AlipayConfig;
import com.thinking.live.config.RechargeConfig;
import com.thinking.live.entity.LiveChargeDO;
import com.thinking.live.entity.pojo.req.LivingCostMiniReq;
import com.thinking.live.entity.pojo.req.LivingCostReq;
import com.thinking.live.entity.pojo.req.RechargeMoneyReq;
import com.thinking.live.entity.pojo.resp.RechargeMoneyResp;
import com.thinking.live.enums.LivChargeEnum;
import com.thinking.live.mapper.LiveChargeMapper;
import com.thinking.live.mapper.LiveProductMapper;
import com.thinking.live.service.LiveChargeService;
import com.thinking.live.service.RechargeMoneyService;
import com.thinking.live.vo.dto.OrderPayResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author Administrator
* @description 针对表【hm_live_charge(本地生活缴费功能订单列表)】的数据库操作Service实现
 *
* @createDate 2023-12-01 14:56:03
*/
@Service
@Slf4j
public class LiveChargeServiceImpl extends ServiceImpl<LiveChargeMapper, LiveChargeDO>
    implements LiveChargeService {

    @Resource
    LiveChargeMapper liveChargeMapper;
    @Resource
    RechargeMoneyService rechargeMoneyService;



    @Resource
    AlipayConfig alipayConfig;
    @Resource
    private RechargeConfig rechargeConfig;

    @Override
    public Map<Object, Object> queryDayLimit() {
        Object number = 0;
//                mallRedisTemplate.opsForValue().get(String.format(Constant.REDIS.LIVING_NUMBER, DateUtil.format(new Date(), "yyyyMMdd")));
        return MapUtil.builder().put("dayNumber", number == null ? 0 : number).put("dayLimit", rechargeConfig.getDayLimitNumber()).build();
    }

    public String queryDianFeiArea() {
        return "[{\"id\":12,\"city_name\":\"安徽\",\"sort\":0,\"initial\":\"A\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":54,\"city_name\":\"亳州市\",\"sort\":0,\"initial\":\"B\",\"pid\":12},{\"id\":48,\"city_name\":\"六安市\",\"sort\":0,\"initial\":\"L\",\"pid\":12},{\"id\":44,\"city_name\":\"合肥市\",\"sort\":0,\"initial\":\"H\",\"pid\":12},{\"id\":38,\"city_name\":\"安庆市\",\"sort\":0,\"initial\":\"A\",\"pid\":12},{\"id\":53,\"city_name\":\"宣城市\",\"sort\":0,\"initial\":\"X\",\"pid\":12},{\"id\":50,\"city_name\":\"宿州市\",\"sort\":0,\"initial\":\"S\",\"pid\":12},{\"id\":42,\"city_name\":\"池州市\",\"sort\":0,\"initial\":\"C\",\"pid\":12},{\"id\":46,\"city_name\":\"淮北市\",\"sort\":0,\"initial\":\"H\",\"pid\":12},{\"id\":45,\"city_name\":\"淮南市\",\"sort\":0,\"initial\":\"H\",\"pid\":12},{\"id\":41,\"city_name\":\"滁州市\",\"sort\":0,\"initial\":\"C\",\"pid\":12},{\"id\":52,\"city_name\":\"芜湖市\",\"sort\":0,\"initial\":\"W\",\"pid\":12},{\"id\":40,\"city_name\":\"蚌埠市\",\"sort\":0,\"initial\":\"B\",\"pid\":12},{\"id\":57,\"city_name\":\"铜陵市\",\"sort\":0,\"initial\":\"T\",\"pid\":12},{\"id\":43,\"city_name\":\"阜阳市\",\"sort\":0,\"initial\":\"F\",\"pid\":12},{\"id\":49,\"city_name\":\"马鞍山市\",\"sort\":0,\"initial\":\"M\",\"pid\":12},{\"id\":47,\"city_name\":\"黄山市\",\"sort\":0,\"initial\":\"H\",\"pid\":12}]},{\"id\":1,\"city_name\":\"北京\",\"sort\":0,\"initial\":\"B\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":55,\"city_name\":\"北京市\",\"sort\":0,\"initial\":\"B\",\"pid\":1}]},{\"id\":23,\"city_name\":\"重庆市\",\"sort\":0,\"initial\":\"C\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":56,\"city_name\":\"重庆市\",\"sort\":0,\"initial\":\"C\",\"pid\":23}]},{\"id\":13,\"city_name\":\"福建\",\"sort\":0,\"initial\":\"F\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":64,\"city_name\":\"三明市\",\"sort\":0,\"initial\":\"S\",\"pid\":13},{\"id\":60,\"city_name\":\"南平市\",\"sort\":0,\"initial\":\"N\",\"pid\":13},{\"id\":65,\"city_name\":\"厦门市\",\"sort\":0,\"initial\":\"X\",\"pid\":13},{\"id\":61,\"city_name\":\"宁德市\",\"sort\":0,\"initial\":\"N\",\"pid\":13},{\"id\":63,\"city_name\":\"泉州市\",\"sort\":0,\"initial\":\"Q\",\"pid\":13},{\"id\":66,\"city_name\":\"漳州市\",\"sort\":0,\"initial\":\"Z\",\"pid\":13},{\"id\":58,\"city_name\":\"福州市\",\"sort\":0,\"initial\":\"F\",\"pid\":13},{\"id\":62,\"city_name\":\"莆田市\",\"sort\":0,\"initial\":\"P\",\"pid\":13},{\"id\":51,\"city_name\":\"铜陵市\",\"sort\":0,\"initial\":\"T\",\"pid\":13},{\"id\":59,\"city_name\":\"龙岩市\",\"sort\":0,\"initial\":\"L\",\"pid\":13}]},{\"id\":20,\"city_name\":\"广东\",\"sort\":0,\"initial\":\"G\",\"need_ytype\":1,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":68,\"city_name\":\"东莞市\",\"sort\":0,\"initial\":\"D\",\"pid\":20},{\"id\":84,\"city_name\":\"中山市\",\"sort\":0,\"initial\":\"Z\",\"pid\":20},{\"id\":83,\"city_name\":\"云浮市\",\"sort\":0,\"initial\":\"Y\",\"pid\":20},{\"id\":69,\"city_name\":\"佛山市\",\"sort\":0,\"initial\":\"F\",\"pid\":20},{\"id\":70,\"city_name\":\"广州市\",\"sort\":0,\"initial\":\"G\",\"pid\":20},{\"id\":71,\"city_name\":\"惠州市\",\"sort\":0,\"initial\":\"H\",\"pid\":20},{\"id\":73,\"city_name\":\"揭阳市\",\"sort\":0,\"initial\":\"J\",\"pid\":20},{\"id\":76,\"city_name\":\"梅州市\",\"sort\":0,\"initial\":\"M\",\"pid\":20},{\"id\":80,\"city_name\":\"汕头市\",\"sort\":0,\"initial\":\"S\",\"pid\":20},{\"id\":81,\"city_name\":\"汕尾市\",\"sort\":0,\"initial\":\"S\",\"pid\":20},{\"id\":74,\"city_name\":\"江门市\",\"sort\":0,\"initial\":\"J\",\"pid\":20},{\"id\":72,\"city_name\":\"河源市\",\"sort\":0,\"initial\":\"H\",\"pid\":20},{\"id\":79,\"city_name\":\"深圳市\",\"sort\":0,\"initial\":\"S\",\"pid\":20},{\"id\":77,\"city_name\":\"清远市\",\"sort\":0,\"initial\":\"Q\",\"pid\":20},{\"id\":86,\"city_name\":\"湛江市\",\"sort\":0,\"initial\":\"Z\",\"pid\":20},{\"id\":67,\"city_name\":\"潮州市\",\"sort\":0,\"initial\":\"C\",\"pid\":20},{\"id\":85,\"city_name\":\"珠海市\",\"sort\":0,\"initial\":\"Z\",\"pid\":20},{\"id\":87,\"city_name\":\"肇庆市\",\"sort\":0,\"initial\":\"Z\",\"pid\":20},{\"id\":75,\"city_name\":\"茂名市\",\"sort\":0,\"initial\":\"M\",\"pid\":20},{\"id\":82,\"city_name\":\"阳江市\",\"sort\":0,\"initial\":\"Y\",\"pid\":20},{\"id\":78,\"city_name\":\"韶关市\",\"sort\":0,\"initial\":\"S\",\"pid\":20}]},{\"id\":21,\"city_name\":\"广西\",\"sort\":0,\"initial\":\"G\",\"need_ytype\":1,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":88,\"city_name\":\"北海市\",\"sort\":0,\"initial\":\"B\",\"pid\":21},{\"id\":98,\"city_name\":\"南宁市\",\"sort\":0,\"initial\":\"N\",\"pid\":21},{\"id\":90,\"city_name\":\"崇左市\",\"sort\":0,\"initial\":\"C\",\"pid\":21},{\"id\":97,\"city_name\":\"来宾市\",\"sort\":0,\"initial\":\"L\",\"pid\":21},{\"id\":96,\"city_name\":\"柳州市\",\"sort\":0,\"initial\":\"L\",\"pid\":21},{\"id\":92,\"city_name\":\"桂林市\",\"sort\":0,\"initial\":\"G\",\"pid\":21},{\"id\":100,\"city_name\":\"梧州市\",\"sort\":0,\"initial\":\"W\",\"pid\":21},{\"id\":95,\"city_name\":\"河池市\",\"sort\":0,\"initial\":\"H\",\"pid\":21},{\"id\":101,\"city_name\":\"玉林市\",\"sort\":0,\"initial\":\"Y\",\"pid\":21},{\"id\":89,\"city_name\":\"百色市\",\"sort\":0,\"initial\":\"B\",\"pid\":21},{\"id\":93,\"city_name\":\"贵港市\",\"sort\":0,\"initial\":\"G\",\"pid\":21},{\"id\":94,\"city_name\":\"贺州市\",\"sort\":0,\"initial\":\"H\",\"pid\":21},{\"id\":99,\"city_name\":\"钦州市\",\"sort\":0,\"initial\":\"Q\",\"pid\":21},{\"id\":91,\"city_name\":\"防城港市\",\"sort\":0,\"initial\":\"F\",\"pid\":21}]},{\"id\":25,\"city_name\":\"贵州\",\"sort\":0,\"initial\":\"G\",\"need_ytype\":1,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":105,\"city_name\":\"六盘水市\",\"sort\":0,\"initial\":\"L\",\"pid\":25},{\"id\":102,\"city_name\":\"安顺市\",\"sort\":0,\"initial\":\"A\",\"pid\":25},{\"id\":103,\"city_name\":\"毕节市\",\"sort\":0,\"initial\":\"B\",\"pid\":25},{\"id\":104,\"city_name\":\"贵阳市\",\"sort\":0,\"initial\":\"G\",\"pid\":25},{\"id\":110,\"city_name\":\"遵义市\",\"sort\":0,\"initial\":\"Z\",\"pid\":25},{\"id\":109,\"city_name\":\"铜仁市\",\"sort\":0,\"initial\":\"T\",\"pid\":25},{\"id\":107,\"city_name\":\"黔东南苗族侗族自治州\",\"sort\":0,\"initial\":\"Q\",\"pid\":25},{\"id\":108,\"city_name\":\"黔南布依族苗族自治州\",\"sort\":0,\"initial\":\"Q\",\"pid\":25},{\"id\":106,\"city_name\":\"黔西南布依族苗族自治州\",\"sort\":0,\"initial\":\"Q\",\"pid\":25}]},{\"id\":29,\"city_name\":\"甘肃\",\"sort\":0,\"initial\":\"G\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":119,\"city_name\":\"临夏回族自治州\",\"sort\":0,\"initial\":\"L\",\"pid\":29},{\"id\":117,\"city_name\":\"兰州市\",\"sort\":0,\"initial\":\"L\",\"pid\":29},{\"id\":114,\"city_name\":\"嘉峪关市\",\"sort\":0,\"initial\":\"J\",\"pid\":29},{\"id\":122,\"city_name\":\"天水市\",\"sort\":0,\"initial\":\"T\",\"pid\":29},{\"id\":112,\"city_name\":\"定西市\",\"sort\":0,\"initial\":\"D\",\"pid\":29},{\"id\":120,\"city_name\":\"平凉市\",\"sort\":0,\"initial\":\"P\",\"pid\":29},{\"id\":121,\"city_name\":\"庆阳市\",\"sort\":0,\"initial\":\"Q\",\"pid\":29},{\"id\":124,\"city_name\":\"张掖市\",\"sort\":0,\"initial\":\"Z\",\"pid\":29},{\"id\":123,\"city_name\":\"武威市\",\"sort\":0,\"initial\":\"W\",\"pid\":29},{\"id\":113,\"city_name\":\"甘南藏族自治州\",\"sort\":0,\"initial\":\"G\",\"pid\":29},{\"id\":111,\"city_name\":\"白银市\",\"sort\":0,\"initial\":\"B\",\"pid\":29},{\"id\":116,\"city_name\":\"酒泉市\",\"sort\":0,\"initial\":\"J\",\"pid\":29},{\"id\":115,\"city_name\":\"金昌市\",\"sort\":0,\"initial\":\"J\",\"pid\":29},{\"id\":118,\"city_name\":\"陇南市\",\"sort\":0,\"initial\":\"L\",\"pid\":29}]},{\"id\":3,\"city_name\":\"河北\",\"sort\":0,\"initial\":\"H\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":125,\"city_name\":\"保定市\",\"sort\":0,\"initial\":\"B\",\"pid\":3},{\"id\":133,\"city_name\":\"唐山市\",\"sort\":0,\"initial\":\"T\",\"pid\":3},{\"id\":130,\"city_name\":\"廊坊市\",\"sort\":0,\"initial\":\"L\",\"pid\":3},{\"id\":135,\"city_name\":\"张家口市\",\"sort\":0,\"initial\":\"Z\",\"pid\":3},{\"id\":126,\"city_name\":\"承德市\",\"sort\":0,\"initial\":\"C\",\"pid\":3},{\"id\":127,\"city_name\":\"沧州市\",\"sort\":0,\"initial\":\"C\",\"pid\":3},{\"id\":132,\"city_name\":\"石家庄市\",\"sort\":0,\"initial\":\"S\",\"pid\":3},{\"id\":131,\"city_name\":\"秦皇岛市\",\"sort\":0,\"initial\":\"Q\",\"pid\":3},{\"id\":129,\"city_name\":\"衡水市\",\"sort\":0,\"initial\":\"H\",\"pid\":3},{\"id\":134,\"city_name\":\"邢台市\",\"sort\":0,\"initial\":\"X\",\"pid\":3},{\"id\":128,\"city_name\":\"邯郸市\",\"sort\":0,\"initial\":\"H\",\"pid\":3}]},{\"id\":8,\"city_name\":\"黑龙江\",\"sort\":0,\"initial\":\"H\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":145,\"city_name\":\"七台河市\",\"sort\":0,\"initial\":\"Q\",\"pid\":8},{\"id\":148,\"city_name\":\"伊春市\",\"sort\":0,\"initial\":\"Y\",\"pid\":8},{\"id\":142,\"city_name\":\"佳木斯市\",\"sort\":0,\"initial\":\"J\",\"pid\":8},{\"id\":146,\"city_name\":\"双鸭山市\",\"sort\":0,\"initial\":\"S\",\"pid\":8},{\"id\":138,\"city_name\":\"哈尔滨市\",\"sort\":0,\"initial\":\"H\",\"pid\":8},{\"id\":137,\"city_name\":\"大兴安岭地区\",\"sort\":0,\"initial\":\"D\",\"pid\":8},{\"id\":136,\"city_name\":\"大庆市\",\"sort\":0,\"initial\":\"D\",\"pid\":8},{\"id\":143,\"city_name\":\"牡丹江市\",\"sort\":0,\"initial\":\"M\",\"pid\":8},{\"id\":147,\"city_name\":\"绥化市\",\"sort\":0,\"initial\":\"S\",\"pid\":8},{\"id\":141,\"city_name\":\"鸡西市\",\"sort\":0,\"initial\":\"J\",\"pid\":8},{\"id\":139,\"city_name\":\"鹤岗市\",\"sort\":0,\"initial\":\"H\",\"pid\":8},{\"id\":140,\"city_name\":\"黑河市\",\"sort\":0,\"initial\":\"H\",\"pid\":8},{\"id\":144,\"city_name\":\"齐齐哈尔市\",\"sort\":0,\"initial\":\"Q\",\"pid\":8}]},{\"id\":17,\"city_name\":\"河南\",\"sort\":0,\"initial\":\"H\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":158,\"city_name\":\"三门峡市\",\"sort\":0,\"initial\":\"S\",\"pid\":17},{\"id\":162,\"city_name\":\"信阳市\",\"sort\":0,\"initial\":\"X\",\"pid\":17},{\"id\":156,\"city_name\":\"南阳市\",\"sort\":0,\"initial\":\"N\",\"pid\":17},{\"id\":165,\"city_name\":\"周口市\",\"sort\":0,\"initial\":\"Z\",\"pid\":17},{\"id\":159,\"city_name\":\"商丘市\",\"sort\":0,\"initial\":\"S\",\"pid\":17},{\"id\":149,\"city_name\":\"安阳市\",\"sort\":0,\"initial\":\"A\",\"pid\":17},{\"id\":157,\"city_name\":\"平顶山市\",\"sort\":0,\"initial\":\"P\",\"pid\":17},{\"id\":154,\"city_name\":\"开封市\",\"sort\":0,\"initial\":\"K\",\"pid\":17},{\"id\":160,\"city_name\":\"新乡市\",\"sort\":0,\"initial\":\"X\",\"pid\":17},{\"id\":155,\"city_name\":\"洛阳市\",\"sort\":0,\"initial\":\"L\",\"pid\":17},{\"id\":153,\"city_name\":\"济源市\",\"sort\":0,\"initial\":\"J\",\"pid\":17},{\"id\":151,\"city_name\":\"漯河市\",\"sort\":0,\"initial\":\"L\",\"pid\":17},{\"id\":163,\"city_name\":\"濮阳市\",\"sort\":0,\"initial\":\"P\",\"pid\":17},{\"id\":152,\"city_name\":\"焦作市\",\"sort\":0,\"initial\":\"J\",\"pid\":17},{\"id\":161,\"city_name\":\"许昌市\",\"sort\":0,\"initial\":\"X\",\"pid\":17},{\"id\":164,\"city_name\":\"郑州市\",\"sort\":0,\"initial\":\"Z\",\"pid\":17},{\"id\":166,\"city_name\":\"驻马店市\",\"sort\":0,\"initial\":\"Z\",\"pid\":17},{\"id\":150,\"city_name\":\"鹤壁市\",\"sort\":0,\"initial\":\"H\",\"pid\":17}]},{\"id\":18,\"city_name\":\"湖北\",\"sort\":0,\"initial\":\"H\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":181,\"city_name\":\"仙桃市\",\"sort\":0,\"initial\":\"X\",\"pid\":18},{\"id\":173,\"city_name\":\"十堰市\",\"sort\":0,\"initial\":\"S\",\"pid\":18},{\"id\":180,\"city_name\":\"咸宁市\",\"sort\":0,\"initial\":\"X\",\"pid\":18},{\"id\":176,\"city_name\":\"天门市\",\"sort\":0,\"initial\":\"T\",\"pid\":18},{\"id\":179,\"city_name\":\"孝感市\",\"sort\":0,\"initial\":\"X\",\"pid\":18},{\"id\":182,\"city_name\":\"宜昌市\",\"sort\":0,\"initial\":\"Y\",\"pid\":18},{\"id\":168,\"city_name\":\"恩施土家族苗族自治州\",\"sort\":0,\"initial\":\"E\",\"pid\":18},{\"id\":177,\"city_name\":\"武汉市\",\"sort\":0,\"initial\":\"W\",\"pid\":18},{\"id\":172,\"city_name\":\"潜江市\",\"sort\":0,\"initial\":\"Q\",\"pid\":18},{\"id\":175,\"city_name\":\"神农架林区\",\"sort\":0,\"initial\":\"S\",\"pid\":18},{\"id\":37,\"city_name\":\"荆州市\",\"sort\":0,\"initial\":\"J\",\"pid\":18},{\"id\":171,\"city_name\":\"荆门市\",\"sort\":0,\"initial\":\"J\",\"pid\":18},{\"id\":178,\"city_name\":\"襄阳市\",\"sort\":0,\"initial\":\"X\",\"pid\":18},{\"id\":167,\"city_name\":\"鄂州市\",\"sort\":0,\"initial\":\"E\",\"pid\":18},{\"id\":174,\"city_name\":\"随州市\",\"sort\":0,\"initial\":\"S\",\"pid\":18},{\"id\":170,\"city_name\":\"黄冈市\",\"sort\":0,\"initial\":\"H\",\"pid\":18},{\"id\":169,\"city_name\":\"黄石市\",\"sort\":0,\"initial\":\"H\",\"pid\":18}]},{\"id\":19,\"city_name\":\"湖南\",\"sort\":0,\"initial\":\"H\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":188,\"city_name\":\"娄底市\",\"sort\":0,\"initial\":\"L\",\"pid\":19},{\"id\":192,\"city_name\":\"岳阳市\",\"sort\":0,\"initial\":\"Y\",\"pid\":19},{\"id\":184,\"city_name\":\"常德市\",\"sort\":0,\"initial\":\"C\",\"pid\":19},{\"id\":196,\"city_name\":\"张家界市\",\"sort\":0,\"initial\":\"Z\",\"pid\":19},{\"id\":187,\"city_name\":\"怀化市\",\"sort\":0,\"initial\":\"H\",\"pid\":19},{\"id\":195,\"city_name\":\"株洲市\",\"sort\":0,\"initial\":\"Z\",\"pid\":19},{\"id\":194,\"city_name\":\"永州市\",\"sort\":0,\"initial\":\"Y\",\"pid\":19},{\"id\":190,\"city_name\":\"湘潭市\",\"sort\":0,\"initial\":\"X\",\"pid\":19},{\"id\":191,\"city_name\":\"湘西土家族苗族自治州\",\"sort\":0,\"initial\":\"X\",\"pid\":19},{\"id\":193,\"city_name\":\"益阳市\",\"sort\":0,\"initial\":\"Y\",\"pid\":19},{\"id\":186,\"city_name\":\"衡阳市\",\"sort\":0,\"initial\":\"H\",\"pid\":19},{\"id\":189,\"city_name\":\"邵阳市\",\"sort\":0,\"initial\":\"S\",\"pid\":19},{\"id\":185,\"city_name\":\"郴州市\",\"sort\":0,\"initial\":\"C\",\"pid\":19},{\"id\":183,\"city_name\":\"长沙市\",\"sort\":0,\"initial\":\"C\",\"pid\":19}]},{\"id\":22,\"city_name\":\"海南\",\"sort\":0,\"initial\":\"H\",\"need_ytype\":1,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":214,\"city_name\":\"万宁市\",\"sort\":0,\"initial\":\"W\",\"pid\":22},{\"id\":209,\"city_name\":\"三亚市\",\"sort\":0,\"initial\":\"S\",\"pid\":22},{\"id\":210,\"city_name\":\"三沙市\",\"sort\":0,\"initial\":\"S\",\"pid\":22},{\"id\":201,\"city_name\":\"东方市\",\"sort\":0,\"initial\":\"D\",\"pid\":22},{\"id\":204,\"city_name\":\"临高县\",\"sort\":0,\"initial\":\"L\",\"pid\":22},{\"id\":205,\"city_name\":\"乐东黎族自治县\",\"sort\":0,\"initial\":\"L\",\"pid\":22},{\"id\":212,\"city_name\":\"五指山市\",\"sort\":0,\"initial\":\"W\",\"pid\":22},{\"id\":198,\"city_name\":\"保亭黎族苗族自治县\",\"sort\":0,\"initial\":\"B\",\"pid\":22},{\"id\":215,\"city_name\":\"儋州市\",\"sort\":0,\"initial\":\"Z\",\"pid\":22},{\"id\":202,\"city_name\":\"定安县\",\"sort\":0,\"initial\":\"D\",\"pid\":22},{\"id\":211,\"city_name\":\"屯昌县\",\"sort\":0,\"initial\":\"T\",\"pid\":22},{\"id\":213,\"city_name\":\"文昌市\",\"sort\":0,\"initial\":\"W\",\"pid\":22},{\"id\":200,\"city_name\":\"昌江黎族自治县\",\"sort\":0,\"initial\":\"C\",\"pid\":22},{\"id\":203,\"city_name\":\"海口市\",\"sort\":0,\"initial\":\"H\",\"pid\":22},{\"id\":199,\"city_name\":\"澄迈县\",\"sort\":0,\"initial\":\"C\",\"pid\":22},{\"id\":208,\"city_name\":\"琼中黎族苗族自治县\",\"sort\":0,\"initial\":\"Q\",\"pid\":22},{\"id\":207,\"city_name\":\"琼海市\",\"sort\":0,\"initial\":\"Q\",\"pid\":22},{\"id\":197,\"city_name\":\"白沙黎族自治县\",\"sort\":0,\"initial\":\"B\",\"pid\":22},{\"id\":206,\"city_name\":\"陵水黎族自治县\",\"sort\":0,\"initial\":\"L\",\"pid\":22}]},{\"id\":7,\"city_name\":\"吉林\",\"sort\":0,\"initial\":\"J\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":219,\"city_name\":\"吉林市\",\"sort\":0,\"initial\":\"J\",\"pid\":7},{\"id\":221,\"city_name\":\"四平市\",\"sort\":0,\"initial\":\"S\",\"pid\":7},{\"id\":224,\"city_name\":\"延边朝鲜族自治州\",\"sort\":0,\"initial\":\"Y\",\"pid\":7},{\"id\":222,\"city_name\":\"松原市\",\"sort\":0,\"initial\":\"S\",\"pid\":7},{\"id\":217,\"city_name\":\"白城市\",\"sort\":0,\"initial\":\"B\",\"pid\":7},{\"id\":216,\"city_name\":\"白山市\",\"sort\":0,\"initial\":\"B\",\"pid\":7},{\"id\":220,\"city_name\":\"辽源市\",\"sort\":0,\"initial\":\"L\",\"pid\":7},{\"id\":223,\"city_name\":\"通化市\",\"sort\":0,\"initial\":\"T\",\"pid\":7},{\"id\":218,\"city_name\":\"长春市\",\"sort\":0,\"initial\":\"C\",\"pid\":7}]},{\"id\":10,\"city_name\":\"江苏\",\"sort\":0,\"initial\":\"J\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":228,\"city_name\":\"南京市\",\"sort\":0,\"initial\":\"N\",\"pid\":10},{\"id\":229,\"city_name\":\"南通市\",\"sort\":0,\"initial\":\"N\",\"pid\":10},{\"id\":231,\"city_name\":\"宿迁市\",\"sort\":0,\"initial\":\"S\",\"pid\":10},{\"id\":225,\"city_name\":\"常州市\",\"sort\":0,\"initial\":\"C\",\"pid\":10},{\"id\":234,\"city_name\":\"徐州市\",\"sort\":0,\"initial\":\"X\",\"pid\":10},{\"id\":236,\"city_name\":\"扬州市\",\"sort\":0,\"initial\":\"Y\",\"pid\":10},{\"id\":233,\"city_name\":\"无锡市\",\"sort\":0,\"initial\":\"W\",\"pid\":10},{\"id\":232,\"city_name\":\"泰州市\",\"sort\":0,\"initial\":\"T\",\"pid\":10},{\"id\":226,\"city_name\":\"淮安市\",\"sort\":0,\"initial\":\"H\",\"pid\":10},{\"id\":235,\"city_name\":\"盐城市\",\"sort\":0,\"initial\":\"Y\",\"pid\":10},{\"id\":230,\"city_name\":\"苏州市\",\"sort\":0,\"initial\":\"S\",\"pid\":10},{\"id\":227,\"city_name\":\"连云港市\",\"sort\":0,\"initial\":\"L\",\"pid\":10},{\"id\":237,\"city_name\":\"镇江市\",\"sort\":0,\"initial\":\"Z\",\"pid\":10}]},{\"id\":14,\"city_name\":\"江西\",\"sort\":0,\"initial\":\"J\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":245,\"city_name\":\"上饶市\",\"sort\":0,\"initial\":\"S\",\"pid\":14},{\"id\":241,\"city_name\":\"九江市\",\"sort\":0,\"initial\":\"J\",\"pid\":14},{\"id\":243,\"city_name\":\"南昌市\",\"sort\":0,\"initial\":\"N\",\"pid\":14},{\"id\":242,\"city_name\":\"吉安市\",\"sort\":0,\"initial\":\"J\",\"pid\":14},{\"id\":248,\"city_name\":\"宜春市\",\"sort\":0,\"initial\":\"Y\",\"pid\":14},{\"id\":238,\"city_name\":\"抚州市\",\"sort\":0,\"initial\":\"F\",\"pid\":14},{\"id\":246,\"city_name\":\"新余市\",\"sort\":0,\"initial\":\"X\",\"pid\":14},{\"id\":240,\"city_name\":\"景德镇市\",\"sort\":0,\"initial\":\"J\",\"pid\":14},{\"id\":244,\"city_name\":\"萍乡市\",\"sort\":0,\"initial\":\"P\",\"pid\":14},{\"id\":239,\"city_name\":\"赣州市\",\"sort\":0,\"initial\":\"G\",\"pid\":14},{\"id\":247,\"city_name\":\"鹰潭市\",\"sort\":0,\"initial\":\"Y\",\"pid\":14}]},{\"id\":36,\"city_name\":\"冀北\",\"sort\":0,\"initial\":\"J\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":251,\"city_name\":\"唐山市\",\"sort\":0,\"initial\":\"T\",\"pid\":36},{\"id\":412,\"city_name\":\"廊坊\",\"sort\":0,\"initial\":\"L\",\"pid\":36},{\"id\":252,\"city_name\":\"张家口市\",\"sort\":0,\"initial\":\"Z\",\"pid\":36},{\"id\":249,\"city_name\":\"承德市\",\"sort\":0,\"initial\":\"C\",\"pid\":36},{\"id\":250,\"city_name\":\"秦皇岛市\",\"sort\":0,\"initial\":\"Q\",\"pid\":36}]},{\"id\":6,\"city_name\":\"辽宁\",\"sort\":0,\"initial\":\"L\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":257,\"city_name\":\"丹东市\",\"sort\":0,\"initial\":\"D\",\"pid\":6},{\"id\":256,\"city_name\":\"大连市\",\"sort\":0,\"initial\":\"D\",\"pid\":6},{\"id\":258,\"city_name\":\"抚顺市\",\"sort\":0,\"initial\":\"F\",\"pid\":6},{\"id\":255,\"city_name\":\"朝阳市\",\"sort\":0,\"initial\":\"C\",\"pid\":6},{\"id\":254,\"city_name\":\"本溪市\",\"sort\":0,\"initial\":\"B\",\"pid\":6},{\"id\":264,\"city_name\":\"沈阳市\",\"sort\":0,\"initial\":\"S\",\"pid\":6},{\"id\":263,\"city_name\":\"盘锦市\",\"sort\":0,\"initial\":\"P\",\"pid\":6},{\"id\":266,\"city_name\":\"营口市\",\"sort\":0,\"initial\":\"Y\",\"pid\":6},{\"id\":260,\"city_name\":\"葫芦岛市\",\"sort\":0,\"initial\":\"H\",\"pid\":6},{\"id\":262,\"city_name\":\"辽阳市\",\"sort\":0,\"initial\":\"L\",\"pid\":6},{\"id\":265,\"city_name\":\"铁岭市\",\"sort\":0,\"initial\":\"T\",\"pid\":6},{\"id\":261,\"city_name\":\"锦州市\",\"sort\":0,\"initial\":\"J\",\"pid\":6},{\"id\":259,\"city_name\":\"阜新市\",\"sort\":0,\"initial\":\"F\",\"pid\":6},{\"id\":253,\"city_name\":\"鞍山市\",\"sort\":0,\"initial\":\"A\",\"pid\":6}]},{\"id\":5,\"city_name\":\"蒙东\",\"sort\":0,\"initial\":\"N\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":276,\"city_name\":\"乌兰察布市\",\"sort\":0,\"initial\":\"W\",\"pid\":5},{\"id\":275,\"city_name\":\"乌海市\",\"sort\":0,\"initial\":\"W\",\"pid\":5},{\"id\":277,\"city_name\":\"兴安盟\",\"sort\":0,\"initial\":\"X\",\"pid\":5},{\"id\":268,\"city_name\":\"包头市\",\"sort\":0,\"initial\":\"B\",\"pid\":5},{\"id\":273,\"city_name\":\"呼伦贝尔市\",\"sort\":0,\"initial\":\"H\",\"pid\":5},{\"id\":272,\"city_name\":\"呼和浩特市\",\"sort\":0,\"initial\":\"H\",\"pid\":5},{\"id\":269,\"city_name\":\"巴彦淖尔市\",\"sort\":0,\"initial\":\"B\",\"pid\":5},{\"id\":270,\"city_name\":\"赤峰市\",\"sort\":0,\"initial\":\"C\",\"pid\":5},{\"id\":274,\"city_name\":\"通辽市\",\"sort\":0,\"initial\":\"T\",\"pid\":5},{\"id\":271,\"city_name\":\"鄂尔多斯市\",\"sort\":0,\"initial\":\"E\",\"pid\":5},{\"id\":278,\"city_name\":\"锡林郭勒盟\",\"sort\":0,\"initial\":\"X\",\"pid\":5},{\"id\":267,\"city_name\":\"阿拉善盟\",\"sort\":0,\"initial\":\"A\",\"pid\":5}]},{\"id\":31,\"city_name\":\"宁夏\",\"sort\":0,\"initial\":\"N\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":283,\"city_name\":\"中卫市\",\"sort\":0,\"initial\":\"Z\",\"pid\":31},{\"id\":281,\"city_name\":\"吴忠市\",\"sort\":0,\"initial\":\"W\",\"pid\":31},{\"id\":279,\"city_name\":\"固原市\",\"sort\":0,\"initial\":\"G\",\"pid\":31},{\"id\":280,\"city_name\":\"石嘴山市\",\"sort\":0,\"initial\":\"S\",\"pid\":31},{\"id\":282,\"city_name\":\"银川市\",\"sort\":0,\"initial\":\"Y\",\"pid\":31}]},{\"id\":30,\"city_name\":\"青海\",\"sort\":0,\"initial\":\"Q\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":284,\"city_name\":\"果洛藏族自治州\",\"sort\":0,\"initial\":\"G\",\"pid\":30},{\"id\":285,\"city_name\":\"海东市\",\"sort\":0,\"initial\":\"H\",\"pid\":30},{\"id\":286,\"city_name\":\"海北藏族自治州\",\"sort\":0,\"initial\":\"H\",\"pid\":30},{\"id\":288,\"city_name\":\"海南藏族自治州\",\"sort\":0,\"initial\":\"H\",\"pid\":30},{\"id\":289,\"city_name\":\"海西蒙古族藏族自治州\",\"sort\":0,\"initial\":\"H\",\"pid\":30},{\"id\":291,\"city_name\":\"玉树藏族自治州\",\"sort\":0,\"initial\":\"Y\",\"pid\":30},{\"id\":290,\"city_name\":\"西宁市\",\"sort\":0,\"initial\":\"X\",\"pid\":30},{\"id\":287,\"city_name\":\"黄南藏族自治州\",\"sort\":0,\"initial\":\"H\",\"pid\":30}]},{\"id\":4,\"city_name\":\"山西\",\"sort\":0,\"initial\":\"S\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":296,\"city_name\":\"临汾市\",\"sort\":0,\"initial\":\"L\",\"pid\":4},{\"id\":297,\"city_name\":\"吕梁市\",\"sort\":0,\"initial\":\"L\",\"pid\":4},{\"id\":293,\"city_name\":\"大同市\",\"sort\":0,\"initial\":\"D\",\"pid\":4},{\"id\":299,\"city_name\":\"太原市\",\"sort\":0,\"initial\":\"T\",\"pid\":4},{\"id\":300,\"city_name\":\"忻州市\",\"sort\":0,\"initial\":\"X\",\"pid\":4},{\"id\":295,\"city_name\":\"晋中市\",\"sort\":0,\"initial\":\"J\",\"pid\":4},{\"id\":294,\"city_name\":\"晋城市\",\"sort\":0,\"initial\":\"J\",\"pid\":4},{\"id\":298,\"city_name\":\"朔州市\",\"sort\":0,\"initial\":\"S\",\"pid\":4},{\"id\":302,\"city_name\":\"运城市\",\"sort\":0,\"initial\":\"Y\",\"pid\":4},{\"id\":292,\"city_name\":\"长治市\",\"sort\":0,\"initial\":\"C\",\"pid\":4},{\"id\":301,\"city_name\":\"阳泉市\",\"sort\":0,\"initial\":\"Y\",\"pid\":4}]},{\"id\":9,\"city_name\":\"上海市\",\"sort\":0,\"initial\":\"S\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":303,\"city_name\":\"上海市\",\"sort\":0,\"initial\":\"S\",\"pid\":9}]},{\"id\":15,\"city_name\":\"山东\",\"sort\":0,\"initial\":\"S\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":305,\"city_name\":\"东营市\",\"sort\":0,\"initial\":\"D\",\"pid\":15},{\"id\":310,\"city_name\":\"临沂市\",\"sort\":0,\"initial\":\"L\",\"pid\":15},{\"id\":316,\"city_name\":\"威海市\",\"sort\":0,\"initial\":\"W\",\"pid\":15},{\"id\":306,\"city_name\":\"德州市\",\"sort\":0,\"initial\":\"D\",\"pid\":15},{\"id\":313,\"city_name\":\"日照市\",\"sort\":0,\"initial\":\"R\",\"pid\":15},{\"id\":319,\"city_name\":\"枣庄市\",\"sort\":0,\"initial\":\"Z\",\"pid\":15},{\"id\":314,\"city_name\":\"泰安市\",\"sort\":0,\"initial\":\"T\",\"pid\":15},{\"id\":308,\"city_name\":\"济南市\",\"sort\":0,\"initial\":\"J\",\"pid\":15},{\"id\":309,\"city_name\":\"济宁市\",\"sort\":0,\"initial\":\"J\",\"pid\":15},{\"id\":318,\"city_name\":\"淄博市\",\"sort\":0,\"initial\":\"Z\",\"pid\":15},{\"id\":304,\"city_name\":\"滨州市\",\"sort\":0,\"initial\":\"B\",\"pid\":15},{\"id\":315,\"city_name\":\"潍坊市\",\"sort\":0,\"initial\":\"W\",\"pid\":15},{\"id\":317,\"city_name\":\"烟台市\",\"sort\":0,\"initial\":\"Y\",\"pid\":15},{\"id\":311,\"city_name\":\"聊城市\",\"sort\":0,\"initial\":\"L\",\"pid\":15},{\"id\":307,\"city_name\":\"菏泽市\",\"sort\":0,\"initial\":\"H\",\"pid\":15},{\"id\":312,\"city_name\":\"青岛市\",\"sort\":0,\"initial\":\"Q\",\"pid\":15}]},{\"id\":24,\"city_name\":\"四川\",\"sort\":0,\"initial\":\"S\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":328,\"city_name\":\"乐山市\",\"sort\":0,\"initial\":\"L\",\"pid\":24},{\"id\":332,\"city_name\":\"内江市\",\"sort\":0,\"initial\":\"N\",\"pid\":24},{\"id\":329,\"city_name\":\"凉山彝族自治州\",\"sort\":0,\"initial\":\"L\",\"pid\":24},{\"id\":333,\"city_name\":\"南充市\",\"sort\":0,\"initial\":\"N\",\"pid\":24},{\"id\":336,\"city_name\":\"宜宾市\",\"sort\":0,\"initial\":\"Y\",\"pid\":24},{\"id\":321,\"city_name\":\"巴中市\",\"sort\":0,\"initial\":\"B\",\"pid\":24},{\"id\":325,\"city_name\":\"广元市\",\"sort\":0,\"initial\":\"G\",\"pid\":24},{\"id\":326,\"city_name\":\"广安市\",\"sort\":0,\"initial\":\"G\",\"pid\":24},{\"id\":323,\"city_name\":\"德阳市\",\"sort\":0,\"initial\":\"D\",\"pid\":24},{\"id\":322,\"city_name\":\"成都市\",\"sort\":0,\"initial\":\"C\",\"pid\":24},{\"id\":334,\"city_name\":\"攀枝花市\",\"sort\":0,\"initial\":\"P\",\"pid\":24},{\"id\":339,\"city_name\":\"泸州市\",\"sort\":0,\"initial\":\"L\",\"pid\":24},{\"id\":327,\"city_name\":\"甘孜藏族自治州\",\"sort\":0,\"initial\":\"G\",\"pid\":24},{\"id\":331,\"city_name\":\"眉山市\",\"sort\":0,\"initial\":\"M\",\"pid\":24},{\"id\":330,\"city_name\":\"绵阳市\",\"sort\":0,\"initial\":\"M\",\"pid\":24},{\"id\":338,\"city_name\":\"自贡市\",\"sort\":0,\"initial\":\"Z\",\"pid\":24},{\"id\":340,\"city_name\":\"资阳市\",\"sort\":0,\"initial\":\"Z\",\"pid\":24},{\"id\":324,\"city_name\":\"达州市\",\"sort\":0,\"initial\":\"D\",\"pid\":24},{\"id\":335,\"city_name\":\"遂宁市\",\"sort\":0,\"initial\":\"S\",\"pid\":24},{\"id\":320,\"city_name\":\"阿坝藏族羌族自治州\",\"sort\":0,\"initial\":\"A\",\"pid\":24},{\"id\":337,\"city_name\":\"雅安市\",\"sort\":0,\"initial\":\"Y\",\"pid\":24}]},{\"id\":28,\"city_name\":\"陕西\",\"sort\":0,\"initial\":\"S\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":348,\"city_name\":\"咸阳市\",\"sort\":0,\"initial\":\"X\",\"pid\":28},{\"id\":344,\"city_name\":\"商洛市\",\"sort\":0,\"initial\":\"S\",\"pid\":28},{\"id\":341,\"city_name\":\"安康市\",\"sort\":0,\"initial\":\"A\",\"pid\":28},{\"id\":342,\"city_name\":\"宝鸡市\",\"sort\":0,\"initial\":\"B\",\"pid\":28},{\"id\":349,\"city_name\":\"延安市\",\"sort\":0,\"initial\":\"Y\",\"pid\":28},{\"id\":350,\"city_name\":\"榆林市\",\"sort\":0,\"initial\":\"Y\",\"pid\":28},{\"id\":343,\"city_name\":\"汉中市\",\"sort\":0,\"initial\":\"H\",\"pid\":28},{\"id\":346,\"city_name\":\"渭南市\",\"sort\":0,\"initial\":\"W\",\"pid\":28},{\"id\":347,\"city_name\":\"西安市\",\"sort\":0,\"initial\":\"X\",\"pid\":28},{\"id\":345,\"city_name\":\"铜川市\",\"sort\":0,\"initial\":\"T\",\"pid\":28}]},{\"id\":2,\"city_name\":\"天津市\",\"sort\":0,\"initial\":\"T\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":351,\"city_name\":\"天津市\",\"sort\":0,\"initial\":\"T\",\"pid\":2}]},{\"id\":27,\"city_name\":\"西藏自治区\",\"sort\":0,\"initial\":\"X\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":358,\"city_name\":\"山南市\",\"sort\":0,\"initial\":\"S\",\"pid\":27},{\"id\":354,\"city_name\":\"拉萨市\",\"sort\":0,\"initial\":\"L\",\"pid\":27},{\"id\":357,\"city_name\":\"日喀则市\",\"sort\":0,\"initial\":\"R\",\"pid\":27},{\"id\":353,\"city_name\":\"昌都市\",\"sort\":0,\"initial\":\"C\",\"pid\":27},{\"id\":355,\"city_name\":\"林芝市\",\"sort\":0,\"initial\":\"L\",\"pid\":27},{\"id\":356,\"city_name\":\"那曲市\",\"sort\":0,\"initial\":\"N\",\"pid\":27},{\"id\":352,\"city_name\":\"阿里地区\",\"sort\":0,\"initial\":\"A\",\"pid\":27}]},{\"id\":32,\"city_name\":\"新疆\",\"sort\":0,\"initial\":\"X\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":380,\"city_name\":\"乌鲁木齐市\",\"sort\":0,\"initial\":\"W\",\"pid\":32},{\"id\":381,\"city_name\":\"五家渠市\",\"sort\":0,\"initial\":\"W\",\"pid\":32},{\"id\":382,\"city_name\":\"伊犁哈萨克自治州\",\"sort\":0,\"initial\":\"Y\",\"pid\":32},{\"id\":370,\"city_name\":\"克孜勒苏柯尔克孜自治州\",\"sort\":0,\"initial\":\"K\",\"pid\":32},{\"id\":369,\"city_name\":\"克拉玛依市\",\"sort\":0,\"initial\":\"K\",\"pid\":32},{\"id\":364,\"city_name\":\"北屯市\",\"sort\":0,\"initial\":\"B\",\"pid\":32},{\"id\":362,\"city_name\":\"博尔塔拉蒙古自治州\",\"sort\":0,\"initial\":\"B\",\"pid\":32},{\"id\":375,\"city_name\":\"双河市\",\"sort\":0,\"initial\":\"S\",\"pid\":32},{\"id\":372,\"city_name\":\"可克达拉市\",\"sort\":0,\"initial\":\"K\",\"pid\":32},{\"id\":376,\"city_name\":\"吐鲁番市\",\"sort\":0,\"initial\":\"T\",\"pid\":32},{\"id\":367,\"city_name\":\"和田地区\",\"sort\":0,\"initial\":\"H\",\"pid\":32},{\"id\":366,\"city_name\":\"哈密市\",\"sort\":0,\"initial\":\"H\",\"pid\":32},{\"id\":371,\"city_name\":\"喀什地区\",\"sort\":0,\"initial\":\"K\",\"pid\":32},{\"id\":378,\"city_name\":\"图木舒克市\",\"sort\":0,\"initial\":\"T\",\"pid\":32},{\"id\":377,\"city_name\":\"塔城地区\",\"sort\":0,\"initial\":\"T\",\"pid\":32},{\"id\":363,\"city_name\":\"巴音郭楞蒙古自治州\",\"sort\":0,\"initial\":\"B\",\"pid\":32},{\"id\":373,\"city_name\":\"昆玉市\",\"sort\":0,\"initial\":\"K\",\"pid\":32},{\"id\":365,\"city_name\":\"昌吉回族自治州\",\"sort\":0,\"initial\":\"C\",\"pid\":32},{\"id\":374,\"city_name\":\"石河子市\",\"sort\":0,\"initial\":\"S\",\"pid\":32},{\"id\":368,\"city_name\":\"胡杨河市\",\"sort\":0,\"initial\":\"H\",\"pid\":32},{\"id\":379,\"city_name\":\"铁门关市\",\"sort\":0,\"initial\":\"T\",\"pid\":32},{\"id\":359,\"city_name\":\"阿克苏地区\",\"sort\":0,\"initial\":\"A\",\"pid\":32},{\"id\":360,\"city_name\":\"阿勒泰地区\",\"sort\":0,\"initial\":\"A\",\"pid\":32},{\"id\":361,\"city_name\":\"阿拉尔市\",\"sort\":0,\"initial\":\"A\",\"pid\":32}]},{\"id\":26,\"city_name\":\"云南\",\"sort\":0,\"initial\":\"Y\",\"need_ytype\":1,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":391,\"city_name\":\"临沧市\",\"sort\":0,\"initial\":\"L\",\"pid\":26},{\"id\":390,\"city_name\":\"丽江市\",\"sort\":0,\"initial\":\"L\",\"pid\":26},{\"id\":383,\"city_name\":\"保山市\",\"sort\":0,\"initial\":\"B\",\"pid\":26},{\"id\":385,\"city_name\":\"大理白族自治州\",\"sort\":0,\"initial\":\"D\",\"pid\":26},{\"id\":386,\"city_name\":\"德宏傣族景颇族自治州\",\"sort\":0,\"initial\":\"D\",\"pid\":26},{\"id\":392,\"city_name\":\"怒江傈僳族自治州\",\"sort\":0,\"initial\":\"N\",\"pid\":26},{\"id\":395,\"city_name\":\"文山壮族苗族自治州\",\"sort\":0,\"initial\":\"W\",\"pid\":26},{\"id\":389,\"city_name\":\"昆明市\",\"sort\":0,\"initial\":\"K\",\"pid\":26},{\"id\":398,\"city_name\":\"昭通市\",\"sort\":0,\"initial\":\"Z\",\"pid\":26},{\"id\":393,\"city_name\":\"普洱市\",\"sort\":0,\"initial\":\"P\",\"pid\":26},{\"id\":394,\"city_name\":\"曲靖市\",\"sort\":0,\"initial\":\"Q\",\"pid\":26},{\"id\":384,\"city_name\":\"楚雄彝族自治州\",\"sort\":0,\"initial\":\"C\",\"pid\":26},{\"id\":397,\"city_name\":\"玉溪市\",\"sort\":0,\"initial\":\"Y\",\"pid\":26},{\"id\":388,\"city_name\":\"红河哈尼族彝族自治州\",\"sort\":0,\"initial\":\"H\",\"pid\":26},{\"id\":396,\"city_name\":\"西双版纳傣族自治州\",\"sort\":0,\"initial\":\"X\",\"pid\":26},{\"id\":387,\"city_name\":\"迪庆藏族自治州\",\"sort\":0,\"initial\":\"D\",\"pid\":26}]},{\"id\":11,\"city_name\":\"浙江\",\"sort\":0,\"initial\":\"Z\",\"need_ytype\":0,\"need_city\":1,\"pid\":0,\"city\":[{\"id\":403,\"city_name\":\"丽水市\",\"sort\":0,\"initial\":\"L\",\"pid\":11},{\"id\":406,\"city_name\":\"台州市\",\"sort\":0,\"initial\":\"T\",\"pid\":11},{\"id\":401,\"city_name\":\"嘉兴市\",\"sort\":0,\"initial\":\"J\",\"pid\":11},{\"id\":404,\"city_name\":\"宁波市\",\"sort\":0,\"initial\":\"N\",\"pid\":11},{\"id\":399,\"city_name\":\"杭州市\",\"sort\":0,\"initial\":\"H\",\"pid\":11},{\"id\":407,\"city_name\":\"温州市\",\"sort\":0,\"initial\":\"W\",\"pid\":11},{\"id\":400,\"city_name\":\"湖州市\",\"sort\":0,\"initial\":\"H\",\"pid\":11},{\"id\":405,\"city_name\":\"绍兴市\",\"sort\":0,\"initial\":\"S\",\"pid\":11},{\"id\":409,\"city_name\":\"舟山市\",\"sort\":0,\"initial\":\"Z\",\"pid\":11},{\"id\":408,\"city_name\":\"衢州市\",\"sort\":0,\"initial\":\"Q\",\"pid\":11},{\"id\":402,\"city_name\":\"金华市\",\"sort\":0,\"initial\":\"J\",\"pid\":11}]}]"
   ;
    }


        @Override
    public    Map<String, Object>  makeLivingChargeData(LivingCostReq costReq) throws Exception {
        log.info("makeLivingChargeData方法开始!");
        LivChargeEnum livChargeEnum = LivChargeEnum.toProductName(costReq.getProduct());
        if(livChargeEnum.productId.equals("0")){
            /**
             * 暂不支持此业务充值
             */
            return MapUtil.newHashMap();
        }
        if(StrUtil.isEmpty(costReq.getAccount())){
            return MapUtil.newHashMap();
        }
            if(livChargeEnum.type.equals("dianfei")){
                if(StrUtil.length(costReq.getAccount())!=10|| StrUtil.length(costReq.getAccount())!=13){
//                    throw new Exception("国家电表号有误,请阅读国网表号规则须知!");
                }
                if(StrUtil.length(costReq.getArea())<=1||StrUtil.length(costReq.getCity())<=2){
                   throw new Exception("电费充值,归属地必须选择！");
                }
            }

        Long count = this.lambdaQuery().eq(LiveChargeDO::getLiveAccount, costReq.getAccount()).eq(LiveChargeDO::getPayStatus, 1).eq(LiveChargeDO::getLiveRate, 0).count();
        if(!NumberUtil.equals(count,0)){
//            throw  new ResultException("充值成功后方可继续下单，禁止叠加下单！");
        }

        long reqOrderNo= IdUtil.getSnowflakeNextId();
        String  orderNo=StrUtil.equals(livChargeEnum.type,"huafei")?"LC"+reqOrderNo:"SH"+reqOrderNo;
        Map<String, Object> stringObjectMap = null;
        LiveChargeDO liveChargeDO = null;
        try {
//            stringObjectMap = paymentDubboApi.ObtainCertificate(paymentBody);
            liveChargeDO = LiveChargeDO.builder().liveId(reqOrderNo).liveType(livChargeEnum.productName)
                    .liveProduct(livChargeEnum.productId)
                    .liveMoney(livChargeEnum.money)
                    .liveGold(livChargeEnum.gold).livePrice(livChargeEnum.price)
                    .liveAccount(costReq.getAccount())
                    .createTime(new Date())
//                    .area(costReq.getArea())
//                    .city(costReq.getCity()).ytype(costReq.getYtype())
//                    .idCardNo(costReq.getIdCardNo())
                    .payTime(new Date()) .orderNo(orderNo)
                    .userId(1l).liveDesc("缴费"+costReq.getAccount()).build();

            if(livChargeEnum.type.equals("dianfei")){
                liveChargeDO.setArea(costReq.getArea());
                liveChargeDO.setCity(costReq.getCity());
                liveChargeDO.setIdCardNo(costReq.getIdCardNo());
                liveChargeDO.setYtype(costReq.getYtype());
            }


            liveChargeMapper.insert(liveChargeDO);
        } catch (Exception e) {
            log.info("调用支付接口错误：{}", JSONUtil.toJsonStr(e.getMessage()));
            throw new RuntimeException(e);
        }
        log.info("订单实体类：{}", JSONUtil.toJsonStr(liveChargeDO));
//        mallRedisTemplate.opsForValue().set(String.format(liveChargeFlag, costReq.getAccount().trim(), livChargeEnum.productId),stringObjectMap,28, TimeUnit.MINUTES);
        log.info("支付接口返回结果：{}", JSONUtil.toJsonStr(stringObjectMap));
        return stringObjectMap;
    }




    @Override
    public Map<String, Object> makeMiniLivingChargeData(LivingCostMiniReq costReq) throws Exception {
        log.info("makeMiniLivingChargeData方法开始!");
        LivChargeEnum livChargeEnum = LivChargeEnum.toProductName(costReq.getProduct());
//        Object number = mallRedisTemplate.opsForValue().get(String.format(Constant.REDIS.LIVING_NUMBER, DateUtil.format(new Date(), "yyyyMMdd")));
//        if((number==null?0:Integer.parseInt(number.toString()))>=rechargeConfig.getDayLimitNumber()){
//            throw new ResultException("超过每日限电量！");
//        }

        if(livChargeEnum.type.equals("dianfei")){
          if(StrUtil.length(costReq.getAccount())!=10|| StrUtil.length(costReq.getAccount())!=13){
//              throw new ResultException("国家电表号有误,请阅读国网表号规则须知!");
          }
          if(StrUtil.isEmpty(costReq.getArea())||StrUtil.isEmpty(costReq.getCity())){
//              throw new ResultException("电费充值,归属地必须选择！");
          }
        }
        if(livChargeEnum.productId.equals("0")){
            /**
             * 暂不支持此业务充值
             */
            return MapUtil.newHashMap();
        }
        if(StrUtil.isEmpty(costReq.getAccount())){
            return MapUtil.newHashMap();
        }

        Long count = this.lambdaQuery().eq(LiveChargeDO::getLiveAccount, costReq.getAccount()).eq(LiveChargeDO::getPayStatus, 1).eq(LiveChargeDO::getLiveRate, 0).count();
        if(!NumberUtil.equals(count,0)){
          throw  new Exception("充值成功后方可继续下单，禁止叠加下单！");
        }

        long reqOrderNo= IdUtil.getSnowflakeNextId();
        String  orderNo=StrUtil.equals(livChargeEnum.type,"huafei")?"H"+reqOrderNo:"D"+reqOrderNo;
        AlipayClient alipayClient = new DefaultAlipayClient(
                alipayConfig.getServerUrl(),alipayConfig.getAppId(),
                alipayConfig.getPrivateKey(),"json","GBK",
                alipayConfig.getPublicKey(),"RSA2");
        AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
        request.setNotifyUrl("");
        JSONObject bizContent = new JSONObject();
        bizContent.set("out_trade_no", reqOrderNo);
        bizContent.set("total_amount", livChargeEnum.price);
        bizContent.set("subject", livChargeEnum.name);
        bizContent.set("time_expire", DateUtil.offsetMinute(new Date(),30) );
        DateUtil.format(DateUtil.offsetMinute(new Date(),30), "yyyy-MM-dd HH:mm:ss");
//        bizContent.set("product_code", "JSAPI_PAY");
        bizContent.set("product_code", "QUICK_MSECURITY_PAY");

        /**
         * 封装支付信息
         * 反馈前端进行支付
         */
        Map<String, Object> stringObjectMap = null;
        LiveChargeDO liveChargeDO = null;
        try {
            request.setBizContent(bizContent.toString());
            AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
//            String orderStr = response.getBody();
            BeanUtil.beanToMap(response,stringObjectMap,true,true);
            if(response.isSuccess()){
                System.out.println("调用成功");
            } else {
                System.out.println("调用失败");
            }
//            stringObjectMap = paymentDubboApi.ObtainCertificate(paymentBody);
            liveChargeDO = LiveChargeDO.builder().liveId(reqOrderNo).liveType(livChargeEnum.productName)
                    .liveProduct(livChargeEnum.productId)
                    .liveMoney(livChargeEnum.money)
                    .liveGold(livChargeEnum.gold).livePrice(livChargeEnum.price)
                    .liveAccount(costReq.getAccount())
                    .createTime(new Date())
//                    .area(costReq.getArea())
//                    .city(costReq.getCity()).ytype(costReq.getYtype())
//                    .idCardNo(costReq.getIdCardNo())
                    .payTime(new Date()) .orderNo(orderNo)
                    .userId(0l).liveDesc("缴费"+costReq.getAccount()).build();


            if(livChargeEnum.type.equals("dianfei")){
                liveChargeDO.setArea(costReq.getArea());
                liveChargeDO.setCity(costReq.getCity());
                liveChargeDO.setIdCardNo(costReq.getIdCardNo());
                liveChargeDO.setYtype(costReq.getYtype());
            }
            liveChargeMapper.insert(liveChargeDO);
        } catch (Exception e) {
            log.info("调用支付接口错误：{}", JSONUtil.toJsonStr(e.getMessage()));
            throw new RuntimeException(e);
        }
        log.info("订单实体类：{}", JSONUtil.toJsonStr(liveChargeDO));
//        mallRedisTemplate.opsForValue().set(String.format(liveChargeFlag, costReq.getAccount().trim(), livChargeEnum.productId),stringObjectMap,28, TimeUnit.MINUTES);
        log.info("支付接口返回结果：{}",  JSONUtil.toJsonStr(stringObjectMap));
        return stringObjectMap;
    }


    /**
     * 解析到支付成功结果进行业务充值操作
     * @param orderPayResultDTO
     */
    public RechargeMoneyResp sendChargeDataToThird(OrderPayResultDTO orderPayResultDTO){
        /**
         * 业务订单号 查询账单信息
         */
        log.info("订单更新-支付状态：{}",orderPayResultDTO);
        String liveId= orderPayResultDTO.getOrderNo().substring(2);
        LiveChargeDO lc = liveChargeMapper.selectById(liveId);
           if(lc.getPayStatus()==1){
                     return  null;
            }
            lc.setPayOrderNo(orderPayResultDTO.getOutPayOrderNo());
            lc.setPayTime(new Date());
            lc.setPayStatus(1);
            lc.setLiveRate(11);
            liveChargeMapper.updateById(lc);
                /***
                 * 充值成功
                 */
        LivChargeEnum livChargeEnum1 = Arrays.stream(LivChargeEnum.values()).filter(livChargeEnum -> livChargeEnum.productId.equals(lc.getLiveProduct())).findAny().get();
            RechargeMoneyReq rechargeMoneyReq = RechargeMoneyReq.builder().productId(Integer.parseInt(lc.getLiveProduct()))
                    .type(livChargeEnum1.type)
                    .area(lc.getArea()).city(lc.getCity()).ytype(lc.getYtype()).idCardNno(lc.getIdCardNo())
                    .mobile(lc.getLiveAccount()).outTradeNum(lc.getOrderNo()).build();
            RechargeMoneyResp rechargeMoney = rechargeMoneyService.rechargeMoney(rechargeMoneyReq);
               if(ObjectUtil.equals("0",rechargeMoney.getErrno())){
                   log.info("living-charge-data-success::"+rechargeMoney);
                    lc.setLiveDesc(lc.getLiveDesc()+"|系统提交");
                   lc.setLiveRate(0);
               }else {
                   lc.setLiveRate(2);
                   lc.setLiveDesc(lc.getLiveDesc()+"|失败-人工");
                   log.info("living-charge-data:fail:"+rechargeMoney);
               }
                liveChargeMapper.updateById(lc);
               return rechargeMoney;

    }

    @Override
    public boolean refundChargeDataToByAccountThird(String account) {

        List<LiveChargeDO> list = this.lambdaQuery().eq(LiveChargeDO::getLiveAccount, account).eq(LiveChargeDO::getPayStatus, 1)
                .eq(LiveChargeDO::getLiveRate, 0).orderByDesc(LiveChargeDO::getLiveId).last(" limit 3").list();


      return false;
    }

    /***
     * 退款操作
     * @param orderNo
     * @return
     */
    @Override
    public boolean refundChargeDataToThird(String orderNo) {
//             refundChargeDataToThird(orderNo,"缴费-充值失败-自动退款业务");
        String replace = orderNo.substring(2);//获取充值订单号码
        String[] baseNo = replace.split("T");
        LiveChargeDO lc = liveChargeMapper.selectById(baseNo[0]);
        lc.setLiveRate(2);
        lc.setLiveOver(new Date());
        lc.setLiveDesc(lc.getLiveDesc()+(orderNo.indexOf("T")>=1?"|必须退款":"|建议退款"));
        liveChargeMapper.updateById(lc);
        if(baseNo.length>=2){
        log.info("等待系统定时退款:{}",orderNo);
        }else {
            ThreadUtil.safeSleep(1000);
            dubbleSendOrderNo(baseNo[0]);
        }
        return  true;
       // return  refundChargeDataToThird(orderNo,"缴费-充值失败-退款业务{}"+orderNo);
    }
    @Override
    public boolean refundChargeDataToThird(String orderNo, String desc) {
        LiveChargeDO lc = liveChargeMapper.selectById(orderNo.substring(2));
        if(lc.getPayStatus()!=1){
            //仅仅支付成功才可以走退款接口
            return false;
        }
        if(lc.getLiveRate()!=2){
            //仅充值失败可以退款
            return  false;
        }
        lc.setPayStatus(3);
        liveChargeMapper.updateById(lc);
        String  reasonDesc=lc.getLiveAccount()+"-缴费失败-业务自动退款-月中旬充值更快速！";
        if(lc.getLiveDesc().indexOf("失败-人工")>=1||lc.getLiveDesc().indexOf("人工二次提交|必须退款")>=1){
            reasonDesc= lc.getLiveAccount()+"-缴费失败-业务自动退款-请勿再充值，感谢支持！";
        }
//        RefundBody  tenement = RefundBody.builder()
//                .orderNo(orderNo)
//                .actualReason(reasonDesc)
//                .hasGold(true)
//                .goldAccount(lc.getUserId())
//                .actualPrice(lc.getLivePrice())
//                .goldActualPrice(lc.getLiveGold())
//                .fromServer("WAP")
//                .tenement("life").build();
//         Map<String, Object> objectMap = paymentDubboApi.refundOrder(tenement);
//          log.info("rolling-queuen-{}异步退款操作-{}",orderNo,objectMap);
//            if(MapUtil.isNotEmpty(objectMap)&&objectMap.containsValue("SUCCESS")) {
//                lc.setPayStatus(3);
//                lc.setMoneyStatus(4);//原来返回用户
//                lc.setLiveDesc(lc.getLiveDesc()+"退款完成");
//
//            }else {
//                lc.setPayStatus(4);
//                lc.setLiveDesc(lc.getLiveDesc()+"退款失败");
//                DingTalkUtil.sendDingTalkMsg(Arrays.asList("13673374473"), tenement.toString());
//            }
          liveChargeMapper.updateById(lc);

        return  false;
    }

    /**
     * 充值成功给服务提供商进行业务转款
     * @param orderNo
     * @return
     */
    @Override
    public boolean doingChargeMoneyToThird(String orderNo) {
        LiveChargeDO lc = liveChargeMapper.selectById(orderNo.substring(2));
        lc.setLiveRate(1);
        lc.setLiveOver(new Date());
        lc.setLiveDesc(lc.getLiveDesc()+"|充值成功-转账");
        lc.setMoneyStatus(2);//人工打款
        liveChargeMapper.updateById(lc);
        log.info("return-living-data-3：{}",lc);
        return false;
    }

//    @Override
//    public Page queryLivingChargeList(PageReq pageReq) {
//        Page<LiveChargeDO> liveChargeDOPage = new Page<>(pageReq.getPageNum(),pageReq.getPageSize());
//        QueryWrapper<LiveChargeDO> queryWrapper = new QueryWrapper<LiveChargeDO>().eq("user_id",UserHolder.getUserId()).orderByDesc("live_id");
//        Page<LiveChargeDO> page = this.page(liveChargeDOPage, queryWrapper);
////        log.info("分页结果：{}", JSONObject.toJSONString(page));
//        page.getRecords().forEach(liveChargeDO -> {
//            String liveProduct = liveChargeDO.getLiveType();
//            String type = LivChargeEnum.toProductName(liveProduct).type;
//            liveChargeDO.setType(type);
//        });
//        return  page;
//
//    }


    @Override
    public List<Map<Object, Object>> queryLivingType(String type) {

        if(StrUtil.isEmpty(type)){
            type="huafei";
        }
        List<LivChargeEnum> collect = Arrays.stream(LivChargeEnum.values()) .collect(Collectors.toList());
        List< Map<Object, Object> > list = new ArrayList<>();
        String finalType = type;
        collect.forEach(livChargeEnum -> {
            if(StrUtil.equals(finalType,livChargeEnum.type)){
                Map<Object, Object> build = MapUtil.builder().put("name", livChargeEnum.name).put("productName", livChargeEnum.productName)
                        .put("productId", livChargeEnum.productId).put("money", livChargeEnum.money)
                        .put("gold", livChargeEnum.gold).put("price", livChargeEnum.price)
                        .put("desc", livChargeEnum.desc).put("type", livChargeEnum.type).put("parValue", livChargeEnum.parValue).build();
                list.add(build);
            }
        });

        return list;
    }

    @Override
    public LiveChargeDO queryLivingStatus(String liveId) {
        log.info("liveId：{}", liveId);
        LiveChargeDO chargeDO = this.getById(liveId);
        String liveProduct = chargeDO.getLiveType();
        String type = LivChargeEnum.toProductName(liveProduct).type;
        chargeDO.setType(type);
        return  chargeDO;
    }


    /**
     * 二次发送订单-申请再次充值-便于提升成功率
     * @param orderNo
     * @return
     */
    @Override
    public  boolean dubbleSendOrderNo(String orderNo) { ;
        LiveChargeDO lc = liveChargeMapper.selectById(orderNo);
       String newOrderNo=   lc.getOrderNo()+"T"+lc.getLiveProduct();
        /***
         * 充值成功
         */
        String liveProduct = lc.getLiveProduct();
        String type = Arrays.stream(LivChargeEnum.values()).filter(livChargeEnum ->
            StrUtil.equals(livChargeEnum.productId, liveProduct)
        ).findFirst().get().type;
        RechargeMoneyReq rechargeMoneyReq = RechargeMoneyReq.builder().type(type).productId(Integer.parseInt(lc.getLiveProduct()))
                .mobile(lc.getLiveAccount())
                .area(lc.getArea()).city(lc.getCity()).ytype(lc.getYtype()).idCardNno(lc.getIdCardNo())
                .outTradeNum(newOrderNo).build();
        RechargeMoneyResp rechargeMoney = rechargeMoneyService.rechargeMoney(rechargeMoneyReq);
        if(ObjectUtil.equals("0",rechargeMoney.getErrno())){
            log.info("living-charge-data-success::"+rechargeMoney);
            lc.setLiveDesc(lc.getLiveDesc()+"|二次提交");
            lc.setLiveRate(0);
            liveChargeMapper.updateById(lc);
            return  true;
        }else {
            /**
             * 状态延迟 建议走定时器退款业务
             */
            lc.setLiveDesc(lc.getLiveDesc()+"|二次失败-建议退款");
            lc.setLiveOver(new Date());
            log.info("living-charge-data:fail:"+rechargeMoney);
        }
        liveChargeMapper.updateById(lc);
         return false;
    }


    @Override
    public boolean refundChargeOrderNo(String orderNo) {
        refundChargeDataToThird(orderNo,"用户自助退款");
        return false;
    }



}




